package cn.edu.scau.cmi.ema.domain;


import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.Calendar;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.persistence.*;
import javax.xml.bind.annotation.*;
import cn.edu.scau.cmi.ema.domain.*;
import java.util.Set;
import com.alibaba.fastjson.annotation.JSONField;

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllCrawlerknowledges", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge"),
		@NamedQuery(name = "findCrawlerknowledgeByName", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.name = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByNameContaining", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findCrawlerknowledgeByCrawltime", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.crawltime = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByExist", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.exist = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByTitlerownum", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.titlerownum = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByHash", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.hash = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByCrawlerfilestatus", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.crawlerfilestatus = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByDescription", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.description = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByDescriptionContaining", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findAllCrawlerknowledgesByUrl", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.url.id = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeById", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.id = ?1"),
		@NamedQuery(name = "findCrawlerknowledgeByPrimaryKey", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.id = ?1 "),
		@NamedQuery(name = "deleteCrawlerknowledgesByIds", query = "delete Crawlerknowledge where id in (?1)"),
		@NamedQuery(name = "findCrawlerknowledgesByIds", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.id in (?1)"),
		@NamedQuery(name = "findCrawlerknowledgeByPhyscialPrimaryKey", query = "select myCrawlerknowledge from Crawlerknowledge myCrawlerknowledge where  myCrawlerknowledge.url.id = ?1"),
		@NamedQuery(name = "countCrawlerknowledgesByName", query = "select count(myCrawlerknowledge)  from Crawlerknowledge myCrawlerknowledge where myCrawlerknowledge.name like concat('%',?1,'%')") })
@Table(catalog = "ema", name = "crawlerknowledge")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "ema/cn/edu/scau/cmi/ema/domain", name = "Crawlerknowledge")
@XmlRootElement(namespace = "ema/cn/edu/scau/cmi/ema/domain")

public class Crawlerknowledge implements Serializable, Comparable<Crawlerknowledge> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "crawltime")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar crawltime;

	@Column(name = "exist")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean exist;

	@Column(name = "titlerownum")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer titlerownum;

	@Column(name = "hash")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer hash;

	@Column(name = "crawlerfilestatus")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer crawlerfilestatus;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "url", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Url url;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setCrawltime(Calendar crawltime) {
		this.crawltime = crawltime;
	}

	public Calendar getCrawltime() {
		return this.crawltime;
	}

	public void setExist(Boolean exist) {
		this.exist = exist;
	}

	public Boolean getExist() {
		return this.exist;
	}

	public void setTitlerownum(Integer titlerownum) {
		this.titlerownum = titlerownum;
	}

	public Integer getTitlerownum() {
		return this.titlerownum;
	}

	public void setHash(Integer hash) {
		this.hash = hash;
	}

	public Integer getHash() {
		return this.hash;
	}

	public void setCrawlerfilestatus(Integer crawlerfilestatus) {
		this.crawlerfilestatus = crawlerfilestatus;
	}

	public Integer getCrawlerfilestatus() {
		return this.crawlerfilestatus;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void setUrl(Url url) {
		this.url = url;
	}

	public Url getUrl() {
		return url;
	}

	public void copy(Crawlerknowledge that) {

		setId(that.getId());

		setName(that.getName());
		setCrawltime(that.getCrawltime());
		setExist(that.getExist());
		setTitlerownum(that.getTitlerownum());
		setHash(that.getHash());
		setCrawlerfilestatus(that.getCrawlerfilestatus());
		setDescription(that.getDescription());

		setUrl(that.getUrl());

	}

	public Crawlerknowledge() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("crawltime=[").append(crawltime).append("] ");
		buffer.append("exist=[").append(exist).append("] ");
		buffer.append("titlerownum=[").append(titlerownum).append("] ");
		buffer.append("hash=[").append(hash).append("] ");
		buffer.append("crawlerfilestatus=[").append(crawlerfilestatus).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Crawlerknowledge))
			return false;
		Crawlerknowledge comparedCrawlerknowledge = (Crawlerknowledge) obj;
		if (!CheckPropertyEqual(this.url.id, comparedCrawlerknowledge.url.id)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Crawlerknowledge o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
